import sys
import requests
import time
import json
import hashlib

#目标POST地址
url = 'http://jwapp.szitu.cn:806/api/v2/questionnaire/paper/'
#目标id
id = '' ###
#目标token
token = '' ###

m_url = url  + id + '?' + 'token=' + token

#PayLoad头
header = {}
header["Accept"] = "application/json, text/plain, */*"
header["Accept-Encoding"] = "gzip, deflate"
header["Accept-Language"] = "zh-Hans-CN, zh-Hans; q=0.5"
header["Cache-Control"] = "no-cache"
header["Connection"] = "Keep-Alive"
#header["Content-Length"] = "405"
header["Content-Type"] = "application/json; charset=utf-8"
##修改个人学号
header["cookie"] = "token"+token +"; userNo="
header["Host"] = "jwapp.szitu.cn:806"
header["Origin"] = "http://jwapp.szitu.cn:806"
header["Referer"] = "http://jwapp.szitu.cn:806/static/vue/vue/"
header["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"

#问卷读取
key = {}
key["今日体温"] = '2117ee6fd47c4155bccf921110f61612'
key["其他异常情况"] = '8296905f100d466583e5c56c0c6837ed'
key["居住地是否有变化"] = 'dbc4cd814edb4f3286e968e314582403'
key["是否赴重点防疫地区"] = 'ee4d83228fae4daa8fdce87fa3e50a30'
key["家人健康状况"] = '8afc8321c09040db90682959db7b5e6f'

#问卷提交
answer = {}
answer['s' + key["今日体温"]] = {"result":"正常"}
answer['s' + key["其他异常情况"]] = {"result": "H"}
answer['s' + key["居住地是否有变化"]] = {"result": "B"}
answer['s' + key["是否赴重点防疫地区"]] = {"result": "B"}
answer['s' + key["家人健康状况"]] = {"result": "正常"}

#PayLoad构建与Post提交
post_data = {}
post_data["status"] = '1'
post_data["basicParams"] = str(time.strftime("%Y-%m-%d", time.localtime())) + ' 00:00:00'
post_data['commentator'] = '-'
post_data['deviceId'] = '76f2a304-1288-4062-b50d-d875357' ###
post_data['signature'] = ''
post_data['answers'] = answer
tmp = post_data['commentator'] + post_data["basicParams"] + "murp2020"
m = hashlib.md5()
m.update(tmp.encode("UTF-8"))
post_data['verification'] = m.hexdigest()
print(post_data)
res = requests.post(url= m_url, data= json.dumps(post_data),headers = header)
print(res.text)

#Logs记录
path = ("")
localtime = time.localtime(time.time())
ym = time.strftime('%Y%m',time.localtime(time.time()))
day = time.strftime('%d',time.localtime(time.time()))
time = time.strftime('%H%M',time.localtime(time.time()))
with open(path+'\\'+str(ym)+"-"+str(day) +"-"+str(time) +'.txt', 'a',encoding='utf-8') as w:
    w.write(res.text+"-"+day+"-"+time)